package com.hzx.ssm.service.impl;

import com.hzx.ssm.dao.CommentDao;
import com.hzx.ssm.entity.Comment;
import com.hzx.ssm.entity.ResBean;
import com.hzx.ssm.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentDao commentDao;
    @Override
    public ResBean addComment(Comment comment) {
        comment.setComment_time(new Date());
        comment.setComment_id(UUID.randomUUID().toString());
        commentDao.addComment(comment);
        return ResBean.sucess(200,"评论成功");
    }

    @Override
    public ResBean deleteOneById(String comment_id) {
        commentDao.deleteOneById(comment_id);
        return ResBean.sucess(200,"删除成功");
    }

    @Override
    public ResBean deleteMyComment(String comment_id, String user_id) {
        Comment comment = commentDao.findComment(comment_id, user_id);
        if(comment == null)
            return ResBean.sucess(401,"异常删除操作");
        commentDao.deleteOneById(comment_id);
        return ResBean.sucess(200,"删除成功");
    }

    @Override
    public ResBean findCommentToMessage(String message_id) {
        List<Comment> data = commentDao.findCommentToMessage(message_id);
        return ResBean.sucess(200,"查找成功",data);
    }
}
